package com.leyou.test.advices;

import com.leyou.test.exceptions.LyException;
import com.leyou.test.vo.ExceptionVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@Slf4j   //日志
@ControllerAdvice   //拦截所有Controller
public class BasicExceptionAdvice {

    @ExceptionHandler(LyException.class)    //要拦截处理的异常类型
    public ResponseEntity<ExceptionVo> handleException(LyException e) {
        return ResponseEntity.status(e.getStatus()).body(new ExceptionVo(e));
    }
}
